/**
 *轻云蒜瓣商城
 */
Ext.define("PRO.shop.view.shopView",{
    extend: 'Ext.panel.Panel',
    alias: 'widget.shop.shopview',
    layout:'border',
    id:'shopMainEnterPanel',
    bodyStyle:'background:rgb(236, 240, 245);',
   requires:[//引用子类JS
      'PRO.shop.view.usershop.shopMarketView',
      'PRO.shop.view.shopbuy.shopBuyView',
      'PRO.shop.view.cdkey.shopCDKeyInfoView',
      'PRO.shop.view.cdkey.shopCDKeyView',
      'PRO.shop.view.pay.shopPayView',
      'PRO.shop.view.pay.payHintView',
      'PRO.shop.view.pay.payInfoView',
      'PRO.shop.view.pay.payStyleView',
      'PRO.shop.view.useraccount.accountPay',
      'PRO.shop.view.useraccount.account',
      'PRO.shop.view.pay.orderSend',
      'PRO.shop.view.usershop.productIntro',
      'PRO.shop.view.cdkey.shopCouponView'
   ],
   initComponent: function(){
       var me = this;
       JE.loadScript('/pro/shop/resourse/css/shop.css')
       me.defaults = {border:0,bodyPadding:'0 20px 20px 20px',bodyStyle : 'background-color:#ECF0F5;'};
       me.items = [
           me.getNorthPanel(),
           {
               xtype:'container',
               layout:'hbox',
               region:'center',
               itemId:'cardPanel',
               items:[
                   {xtype:'box',flex:1},
                   {
                        xtype:'container',
                        layout:'card',
                        itemId:'box',
                        width:1200,
                        height:'100%',
                        items:{
                            itemId:'shopMarket',
                            xtype:'shop.shopMarketView',
                            margin:'20px 0 0 0',
                            style:'background-color:#ECF0F5',
                        }
                    },
                   {xtype:'box',flex:1},
               ]
           }
       ];


       me.callParent(arguments);
   },
   //导航栏
   getNorthPanel:function(){
      var me=this;
      var headTpl=new Ext.XTemplate(
          '<div style="width:1200px;margin:0 auto;height:63px;">',
            '<ul class="pf-head shopNavBar" style="box-shadow: 0 2px 4px 0 rgba(211,211,211,0.50)">',
                '<tpl for=".">',
                    '<li class="item {cls}" data-type="{type}" style="font-size: 14px;cursor:pointer;display: inline;width: 100%;padding: 5px 20px;border-radius:100px;">{text}</li>',
                '</tpl>',
                '<a class="convertBtn" href="javascript:;"><img src="'+JE.buildCdnUrl('/pro/shop/resourse/dhbtn.png')+'"/><span style="float:left;height:30px;line-height:30px;color:#376BCF;font-size:14px;font-weight:bold;margin-left:8px;">兑换码</span></a>',
            '</ul>',
          '</div>'
      );
      var panel={
          region:'north',
          xtype:'dataview',
          tpl:headTpl,
          margin:'25px 0 0 0',
          store:Ext.create('Ext.data.Store',{
              fields:['text','type','cls'],
               data:[
              {text:'应用商城',type:'shopMarket'},
              {text:'已购产品',type:'buy'},
              {text:'我的账户',type:'accountpay'},
              // {text:'购物车(0)',type:''},
              // {text:'购物车',type:''},
              {text:'订单管理',type:'order'},
              {text:'合同管理',type:'contract'},
              {text:'发票管理',type:'invoice'},
              // {text:'页面详情',type:'productIntro'},
              // {text:'优惠券管理',type:''},
              // {text:'消费记录',type:''},
              // {text:'升级记录',type:''}
          ]}),
          selectedItemCls:'je-shop-head',
          itemSelector: 'li.item',
          selModel:{deselectOnContainerClick:false},
          listeners:{
              itemclick:function(view,record){
                  var card=me.getCmp('cardPanel').getCmp('box');
                  var window='';
                  //
                  if(JE.isNotEmpty(record.get('type'))){
                        if(record.get('type')=='buy'){
                            window = Ext.create('PRO.shop.view.shopbuy.shopBuyView', {
                                itemId:record.get('type')
                            });
                        }else if(record.get('type')=='accountpay'){
                            window = Ext.create('PRO.shop.view.useraccount.account', {
                                itemId:record.get('type')
                            });
                        }else if(record.get('type')=='order'){
                            window = {
                                itemId:'order',
                                border:false,
                                xtype:'panel',
                                layout:'fit',
                                padding:'20px 0 0 0',
                                items:{
                                    xtype:'jemainview',
                                    cls:'orderView',
                                    autoScroll:true,
                                    padding:20,
                                    height:JE.getBodyHeight()-50,
                                    whereSql:" and JE_SAAS_YH_ID='"+JE.USER.zhId+"'", //JE_PAY_ACCOUNT
                                    funcData:JE.getFuncData('V_ORDER_INFO')//我的订单
                                }
                            }
                        }else if(record.get('type')=='invoice'){
                            window = {
                                itemId:'invoice',
                                border:false,
                                xtype:'panel',
                                layout:'fit',
                                padding:'20px 0 0 0',
                                items:{
                                    xtype:'jemainview',
                                    cls:'contractView',
                                    autoScroll:true,
                                    padding:20,
                                    height:JE.getBodyHeight()-50,
                                    whereSql:" and SY_ZHID='"+JE.USER.zhId+"'", //JE_PAY_ACCOUNT
                                    funcData:JE.getFuncData('JE_SAAS_FPGLGN'),//我的订单
                                }
                            }
                        }else if(record.get('type')=='contract'){
                            window = {
                                itemId:'contract',
                                border:false,
                                xtype:'panel',
                                layout:'fit',
                                padding:'20px 0 0 0',
                                items:{
                                    xtype:'jemainview',
                                    cls:'contractView',
                                    autoScroll:true,
                                    padding:20,
                                    whereSql:" and JE_SAAS_YH_ID='"+JE.USER.zhId+"'", //JE_PAY_ACCOUNT
                                    height:JE.getBodyHeight()-50,
                                    funcData:JE.getFuncData('V_CONTRACT_INFO'),//合同管理
                                }
                            }
                        }
                        if(record.get('type')!='shopMarket'){
                            if(!JE.isNotEmpty(card.getCmp(record.get('type')))){
                                card.add(window);
                            }else{
                                card.remove(card.getCmp(record.get('type')));
                                card.add(window);
                            }
                        }
                    card.getLayout().setActiveItem(record.get('type'));
                  }else{
                    JE.alert('功能开发中...敬请期待!');
                  }

              },
              afterrender:function(view){
                 view.getSelectionModel().select(view.store.getAt(0));//默认选中第一个
                 view.getEl().on('click',function(e){
                      if(e.getTarget('.convertBtn',2)){
                          JE.win({
                              border:0,
                              title:'兑换码使用',
                              width:640,
                              layout:'fit',
                              height:490,
                              bodyPadding:'20px 40px 0 40px',
                              default:{border:0},
                              items:[{xtype:'shop.shopcdkeyview'}]
                          }).show();
                      }
                  });
              }
          }
      }
      return panel;
   }, //region: 'south',
   getData:function(orderId){
      //此处请求数据
      var me = this;
      var data ={}
      //请求订单金额
      var orderCharge = JE.ajax({
          url:'/je/shoppingmall/bill/getOrder',
          params:{
              orderId:orderId||''
          }
      });
      //请求账户余额
      var accountMoney = JE.ajax({
          url:'/je/shoppingmall/bill/getAccountInfo',
          params:''
      })
      data = {
          orderCharge:orderCharge,
          accountInfo:accountMoney
      }
      return data
  }
});
